function validateFormBeforeSearch(theForm){
	
    return true;
}


function validateFormBeforeSubmitForProjectEmployeeMaintenance(){
	var reason = "";
	
	if (document.getElementById('categoryId').value == "Select"){
		alert("Please select a category.");
		return false;
	}
	
	if(!validateDates()){
	return false;
	}
	
	if(!validateHours()){
	return false;
	}
    	
    return true;
}

function validateHours(){
   
   var monday = document.getElementById('monday').value;
   if(!isValidHours(monday,'Monday')){
   document.getElementById('monday').style.background = 'Yellow';
   return false;
   }else{
   document.getElementById('monday').style.background = 'white';
   }
   
   var tuesday = document.getElementById('tuesday').value;
   if(!isValidHours(tuesday,'Tuesday')){
   document.getElementById('tuesday').style.background = 'Yellow';
   return false;
   }else{
   document.getElementById('tuesday').style.background = 'white';
   }
   
   var wednesday = document.getElementById('wednesday').value;
   if(!isValidHours(wednesday,'Wednesday')){
   document.getElementById('wednesday').style.background = 'Yellow';
   return false;
   }else{
   document.getElementById('wednesday').style.background = 'white';
   }
   
   var thursday = document.getElementById('thursday').value;
   if(!isValidHours(thursday,'Thursday')){
   document.getElementById('thursday').style.background = 'Yellow';
   return false;
   }else{
   document.getElementById('thursday').style.background = 'white';
   }
   
   var friday = document.getElementById('friday').value;
   if(!isValidHours(friday,'Friday')){
   document.getElementById('friday').style.background = 'Yellow';
   return false;
   }else{
   document.getElementById('friday').style.background = 'white';
   }
   
   var saturday = document.getElementById('saturday').value;
   if(!isValidHours(saturday,'Saturday')){
   document.getElementById('saturday').style.background = 'Yellow';
   return false;
   }else{
   document.getElementById('saturday').style.background = 'white';
   }
   
   var sunday = document.getElementById('sunday').value;
   if(!isValidHours(sunday,'Sunday')){
   document.getElementById('sunday').style.background = 'Yellow';
   return false;
   }else{
   document.getElementById('sunday').style.background = 'white';
   }

  return true;
}






function validateDates(){

var startDateText = document.getElementById('startDateCalender').value;
var endDateText = document.getElementById('endDateCalender').value;

var myList= startDateText.split("/");
var myList1= endDateText.split("/");

startDateText=myList[1]+"/"+myList[0]+"/"+myList[2];
endDateText=myList1[1]+"/"+myList1[0]+"/"+myList1[2];


var startDate= new Date(startDateText);
var endDate = new Date(endDateText);

var startDateMonth = startDate.getMonth()+1;
var endDateMonth = endDate.getMonth()+1;

  
if(startDate.getFullYear()>endDate.getFullYear()){
 
alert("Errors:\n"+"End Date must be greater than or equal to Start Date"); 
return false;
 
}else if(startDate.getFullYear()==endDate.getFullYear()){

if(startDateMonth>endDateMonth){
  alert("Errors:\n"+"End Date must be greater than or equal to Start Date"); 
  return false;
   
 }else if(startDateMonth==endDateMonth){
  if(startDate.getDate()>endDate.getDate()){
    alert("Errors:\n"+"End Date must be greater than or equal to Start Date"); 
    return false; 
   
    }else{
       return true;
     }


 }else{
    return true;
      
 }
  
}else{
 return true;
}

}


function validateMe(fld,name) { 
	var error = "";

	if (fld.value == null || (fld.value != null && fld.value.length == 0) ) {
		fld.style.background = 'Yellow'; 
		error = name+" field has not been filled in.\n";
	} else {
		var numaric = fld.value;
		for(var j=0;j < numaric.length ; j++)
		{
			if(j==0){
			var alphaa = numaric.charAt(j);
			var chCode = alphaa.charCodeAt(0);
			if(chCode == "32"){
				fld.style.background = 'Yellow'; 
				error = name+" should not start with space.\n";
			}
			}
		}
		fld.style.background = 'White';
	}
	return error;  
	}

function isValidHours(hours , fld){

       var ValidChars = "0123456789.";
         var IsValidChar=true;
         var Char;
         for (i = 0; i < hours.length && IsValidChar == true; i++)
         {
            Char = hours.charAt(i);
            if(ValidChars.indexOf(Char) == -1)
            {
            alert("Please enter valid hours in "+fld+".");
            return false;
            }
         }
         
         if(hours>12){
           alert("Please enter valid hours in "+fld+".");
            return false;
         }
         return true;

}

function trim(str) {
	str = str.replace(/^\s+/, '');
	for (var i = str.length - 1; i >= 0; i--) {
		if (/\S/.test(str.charAt(i))) {
			str = str.substring(0, i + 1);
			break;
		}
	}
	return str;
}

function compareProjectEmployeeDates(startDateText,endDateText,projectStartDateText,projectEndDateText){


var myList= startDateText.split("/");
var myList1= endDateText.split("/");
var myList2 = projectStartDateText.split("/");
var myList3 = projectEndDateText.split("/");

startDateText=myList[1]+"/"+myList[0]+"/"+myList[2];
endDateText=myList1[1]+"/"+myList1[0]+"/"+myList1[2];
projectStartDateText =myList2[1]+"/"+myList2[0]+"/"+myList2[2];
projectEndDateText =myList3[1]+"/"+myList3[0]+"/"+myList3[2];

formattedProjectStartDate = myList2[0]+"/"+myList2[1]+"/"+myList2[2];
formattedProjectEndDate = myList3[0]+"/"+myList3[1]+"/"+myList3[2];

var startDate= new Date(startDateText);
var endDate = new Date(endDateText);
var projectStartDate = new Date(projectStartDateText);
var projectEndDate = new Date(projectEndDateText);

var startDateMonth = startDate.getMonth()+1;
var endDateMonth = endDate.getMonth()+1;
var projectStartDateMonth = projectStartDate.getMonth()+1;
var projectEndDateMonth = projectEndDate.getMonth()+1;
  
if(projectStartDate.getFullYear()>startDate.getFullYear()){
 
alert("Errors:\n"+"Project Employee Start date can not be before Project Start date("+formattedProjectStartDate+")"); 
return false;
 
}else if(projectStartDate.getFullYear()==startDate.getFullYear()){

   if(projectStartDateMonth>startDateMonth){
   alert("Errors:\n"+"Project Employee Start date can not be before Project Start date("+formattedProjectStartDate+")"); 
   return false;
   
   }else if(projectStartDateMonth==startDateMonth){
    if(projectStartDate.getDate()>startDate.getDate()){
    alert("Errors:\n"+"Project Employee Start date can not be before Project Start date("+formattedProjectStartDate+")"); 
    return false; 
   
    }
   }
 }

if(startDate.getFullYear()>projectEndDate.getFullYear()){
 
alert("Errors:\n"+"Project Employee Start date can not be after Project End date("+formattedProjectEndDate+")"); 
return false;
 
}else if(startDate.getFullYear()==projectEndDate.getFullYear()){

   if(startDateMonth>projectEndDateMonth){
   alert("Errors:\n"+"Project Employee Start date can not be after  Project End date("+formattedProjectEndDate+")"); 
   return false;
   
   }else if(startDateMonth==projectEndDateMonth){
    if(startDate.getDate()>projectEndDate.getDate()){
    alert("Errors:\n"+"Project Employee Start date can not be after Project End date("+formattedProjectEndDate+")"); 
    return false; 
   
    }

   }
  
}

if(endDate.getFullYear()>projectEndDate.getFullYear()){
 
alert("Errors:\n"+"Project Employee End date can not be after Project End date("+formattedProjectEndDate+")"); 
return false;
 
}else if(endDate.getFullYear()==projectEndDate.getFullYear()){

   if(endDateMonth>projectEndDateMonth){
   alert("Errors:\n"+"Project Employee End date can not be after Project End date("+formattedProjectEndDate+")");  
   return false;
   
   }else if(endDateMonth==projectEndDateMonth){
    if(endDate.getDate()>projectEndDate.getDate()){
    alert("Errors:\n"+"Project Employee End date can not be after Project End date("+formattedProjectEndDate+")");  
    return false; 
   
    }

   }
  
}


if(projectEndDate.getFullYear()<startDate.getFullYear()){
 
alert("Errors:\n"+"Project Employee start date can not be after Project End date("+formattedProjectEndDate+")"); 
return false;
 
}else if(projectEndDate.getFullYear()==startDate.getFullYear()){

   if(projectEndDateMonth<startDateMonth){
   alert("Errors:\n"+"Project Employee start date can not be after Project End date("+formattedProjectEndDate+")"); 
   return false;
   
   }else if(projectEndDateMonth==startDateMonth){
    if(projectEndDate.getDate()<startDate.getDate()){
    alert("Errors:\n"+"Project Employee start date can not be after Project End date("+formattedProjectEndDate+")"); 
    return false; 
   
    }

   }
  
}

return true;

}

